package cn.com.callback

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.elite.EliteBean;
import cn.com.elite.PropertiesUtil;
import cn.com.elite.Util;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
	每日12:30调度
*/
public class DayJobTask implements CallBackInvoke{
	private static final Log log=LogFactory.getLog(DayJobTask.class);
	public void doCallBack(EliteBean eliteBean,String callBack,Map map,String body){
		try {
			def jsonbody = "";
			/**生成邮件文件路径*/
			PropertiesUtil properties = new PropertiesUtil();
			def emaildir = properties.readValue("fileStore")+"/email/"+Util.getNowString("yyyy-MM-dd");
			boolean flag=Util.createDir(emaildir);
			/**调用安正接口更新日历*/
			def url = properties.readValue("crmip")+"SyncCalendar"; //更新日历信息
			def charset = "utf-8"; //设置字符集
			def timeout = 100000; //设置请求超时时间
			def enableSSLflag = 0;
			Util.doHttpPost(url,"",charset,timeout,enableSSLflag);
			/**失败外呼每次任务调度*/
			def smap = eliteBean.chaxun_sql("select count(*) as c1 from c_calendar where workflag=1 and date_i="+Util.getNowString("yyyyMMdd")+" union all select date_i as c1 from c_calendar where workflag=1 and date_i="+Util.getNowString("yyyyMMdd")+"","dataSource");
			int isworkday = smap[0].get("c1");
			def lastworkday = smap[1].get("c1");
			if(isworkday>=1) {
				//同步上一个交易日的数据
				jsonbody = "{\"batch_id\":\"\",\"startdate\":\""+lastworkday+"\",\"enddate\":\""+lastworkday+"\",\"requesttype\": 2,\"dk_system\":\"HSTA\"}";
				url = properties.readValue("crmip")+"OboundFailTrade"; //调用交易失败数据接口
				Util.doHttpPost(url,jsonbody,charset,timeout,enableSSLflag);
			};
			/**同步安正数据中心字典*/
			url = properties.readValue("crmip")+"DictSync"; 
			smap = eliteBean.chaxun_sql("select parameter_type from custom_parameter_type where datasource=2","dataSource");
			for(def i = 0;i < smap.size();i++) {
				jsonbody = "{\"dict_type\":\""+smap[i].get("parameter_type")+"\"}";
				Util.doHttpPost(url,jsonbody,charset,timeout,enableSSLflag);
			};
		}catch(Exception e) {
			log.error("错误代码： ",e);
		}
	}	
}